define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'subject_record/index' + location.search,
                    add_url: 'subject_record/add',
                    edit_url: 'subject_record/edit',
                    del_url: 'subject_record/del',
                    multi_url: 'subject_record/multi',
                    table: 'subject_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'subject_name', title: __('Subject_id'), operate: 'LIKE'},
                        {field: 'counselor', title: __('Counselor'), operate: 'LIKE'},
                        {field: 'score', title: __('Score'),operate:false},
                        {field: 'status', title: __('Status'),searchList: Config.recordstatuslist,operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        // {field: 'max_score', title: __('Max_score')},
                        {field: 'username', title: __('User_id'), operate: 'LIKE'},
                        {field: 'starttime', title: __('Starttime'),operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'endtime', title: __('Endtime'),operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'examtime', title: __('Examtime'),operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'),align:'left', table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [



                                {
                                    name: 'prove',
                                    title: function (row) {
                                        return '查看报告' + '-' + row.subject_name;
                                    },
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    // icon: 'fa fa-check',
                                    text: '查看报告',
                                    url: 'subject_record/report',
                                    extend: 'data-toggle="tooltip"',
                                    // confirm:'确定要审核通过吗?',
                                    visible: function (row) {
                                        if (row['status']==2){
                                        return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                    success: function (data, ret) {
                                        // location.href = ret.data.url;

                                        window.open(ret.data.url, '_blank')

                                        return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                        ]
                        }
                    ]
                ]
            });
         $(".search input").attr('placeholder','请输入测评库');
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
